﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Mechanical;
using YArchitech.HCLoad.Utils;
using YArchitech.Revit;

namespace YArchitech.HCLoad.Export
{
	public class HcXmlRoot : HcXmlElement
	{
		public HcXmlRoot(HcDataManager dataMan) : base(dataMan)
		{
		}

		public override bool WriteElementData(ref XmlElement xmlelem_hcXML)
		{
			bool result = base.WriteElementData(ref xmlelem_hcXML);
			XmlDocument ownerDocument = xmlelem_hcXML.OwnerDocument;
            string unitString = HcUnit.GetUnitString(UnifiedModified.GetDisplayUnitType(base.DataManager.Document, (UnitType)13));
			xmlelem_hcXML.SetAttribute("temperatureUnit", unitString);
            string unitString2 = HcUnit.GetUnitString(UnifiedModified.GetDisplayUnitType(base.DataManager.Document, (UnitType)0));
			xmlelem_hcXML.SetAttribute("lengthUnit", unitString2);
            string unitString3 = HcUnit.GetUnitString(UnifiedModified.GetDisplayUnitType(base.DataManager.Document, (UnitType)1));
			xmlelem_hcXML.SetAttribute("areaUnit", unitString3);
			XmlElement newChild = ownerDocument.CreateElement("Campus");
			new HcXmlCampus(base.DataManager).WriteElementData(ref newChild);
			xmlelem_hcXML.AppendChild(newChild);
			XmlElement newChild2 = ownerDocument.CreateElement("Construction");
			xmlelem_hcXML.AppendChild(newChild2);
			XmlElement newChild3 = ownerDocument.CreateElement("Layer");
			xmlelem_hcXML.AppendChild(newChild3);
			XmlElement newChild4 = ownerDocument.CreateElement("Material");
			xmlelem_hcXML.AppendChild(newChild4);
			XmlElement newChild5 = ownerDocument.CreateElement("WindowType");
			xmlelem_hcXML.AppendChild(newChild5);
			if (base.DataManager.ZoneDictionary.Count<KeyValuePair<ElementId, List<Zone>>>() > 0)
			{
				foreach (KeyValuePair<ElementId, List<Zone>> keyValuePair in base.DataManager.ZoneDictionary)
				{
					foreach (Zone zone in keyValuePair.Value)
					{
						XmlElement newChild6 = ownerDocument.CreateElement("Zone");
						if (new HcXmlZone(zone).WriteElementData(ref newChild6))
						{
							xmlelem_hcXML.AppendChild(newChild6);
						}
					}
				}
			}
			return result;
		}
	}
}
